{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import os\n",
    "import sys\n",
    "import glob\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "PATH_violence = 'video/violence_2'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|████████████████████████████████████████████████████████████████████████████████| 156/156 [01:43<00:00,  1.50it/s]\n"
     ]
    }
   ],
   "source": [
    "# os.makedirs('./data/Violence',exist_ok=True)\n",
    "for path in tqdm(glob.glob(PATH_violence+'/*')):\n",
    "    fname = os.path.basename(path).split('.')[0]\n",
    "    vidcap = cv2.VideoCapture(path)\n",
    "    success,image = vidcap.read()\n",
    "    count = 0\n",
    "    while success:\n",
    "        if count % 5 == 0:\n",
    "            cv2.imwrite(\"./data/Violence/{}-{}.jpg\".format(fname,str(count).zfill(4)),image)     # save frame as JPEG file      \n",
    "        success,image = vidcap.read()\n",
    "        count += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "PATH_nonviolence = 'video/non_violence_2'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|████████████████████████████████████████████████████████████████████████████████| 120/120 [00:26<00:00,  4.50it/s]\n"
     ]
    }
   ],
   "source": [
    "# os.makedirs('./data/NonViolence',exist_ok=True)\n",
    "for path in tqdm(glob.glob(PATH_nonviolence+'/*')):\n",
    "    fname = os.path.basename(path).split('.')[0]\n",
    "    vidcap = cv2.VideoCapture(path)\n",
    "    success,image = vidcap.read()\n",
    "    count = 0\n",
    "    while success:\n",
    "        if count % 5 == 0:\n",
    "            cv2.imwrite(\"./data/NonViolence/{}-{}.jpg\".format(fname,str(count).zfill(4)),image)     # save frame as JPEG file      \n",
    "        success,image = vidcap.read()\n",
    "        count += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
